<template>
  <div>
    <el-row>
      <el-col :span="4" style="text-align: left">
        <el-button @click="gotoList()">News List</el-button>
      </el-col>
      <el-col :span="8" :offset="12" style="text-align: right">
        <el-button type="primary" plain @click="exitLogin()">Exit</el-button>
      </el-col>
    </el-row>
    <div style="margin-top: 15%;">
      <h1 class="">Search for News</h1>
    </div>
    <el-form :model="searchForm" ref="searchForm">
      <el-form-item prop="search">
        <el-row>
          <el-col :span="8" :offset="8">
            <el-input placeholder="Type in what you want"
                      v-model="searchForm.search"
                      @keyup.enter='searchNews()'
                      clearable>
            </el-input>
          </el-col>
          <el-col :span="2">
            <el-button type="primary" @click="searchNews(searchForm.search)">Search</el-button>
          </el-col>
        </el-row>

      </el-form-item>
    </el-form>
    <!--      <el-form :model="loginForm" :rules="loginRules" ref="loginForm">-->
    <!--        <el-form-item prop="username" class="el-form&#45;&#45;inline">-->
    <!--          <el-input-->
    <!--              placeholder="username"-->
    <!--              v-model="loginForm.username"-->
    <!--              clearable>-->
    <!--          </el-input>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item prop="password" class="el-form&#45;&#45;inline">-->
    <!--          <el-input-->
    <!--              placeholder="password"-->
    <!--              v-model="loginForm.password"-->
    <!--              show-password>-->
    <!--          </el-input>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item prop="buttons" class="el-form&#45;&#45;inline">-->
    <!--          <el-button type="primary"  @click="submitForm('loginForm')">Login</el-button>-->
    <!--          <el-button type="primary"  @click="resetForm('loginForm')">Reset</el-button>-->
    <!--          &lt;!&ndash;        <P>&ndash;&gt;-->
    <!--          &lt;!&ndash;          <small>Do not have an account?</small>&ndash;&gt;-->
    <!--          &lt;!&ndash;        </P>&ndash;&gt;-->
    <!--          &lt;!&ndash;        <el-button type="primary" @click="gotoRegistry()">Create an account</el-button>&ndash;&gt;-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
  </div>
</template>

<script>
// @ is an alias to /src
// import {mapMutations} from 'vuex';
import {mapMutations} from "vuex";

export default {
  name: 'Home',
  data() {
    return {
      searchForm: {
        search: '',
      }
    }
  },

  components: {},
  methods: {
    ...mapMutations(['setPageNum', 'delPageNum', 'delToken', 'setUserName', 'delUserName']),
    searchNews(keywords) {
      const _this = this
      this.$router.push({
        path: 'search',
        query: {
          key: keywords
        }
      })
    },
    exitLogin() {
      const _this = this;
      _this.delToken({token: ''});
      _this.delUserName({userName: ''});
      _this.$router.push('/login')
    },
    gotoList() {
      const vm = this;
      vm.$router.push('/news');
    }

  }
}

</script>
